package helper;

import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {
    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(6,()->{
            System.out.println("计数器到达6！");
        });
        for(int i = 0 ; i < 6 ; i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getId()+"--"+Thread.currentThread().getName());
                try {
                    cyclicBarrier.await();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"结束");
            },String.valueOf(i)).start();
        }
    }
}
